package com.mmy.dao.hotel;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.hotel.THotelBase;

public interface THotelBaseRepository extends JpaRepository<THotelBase, Integer> {
	
	/**
	 * 获得最大酒店编号
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人 dingxd
	 * @date 创建日期 2020.11.17
	 */
	@Query(value = "SELECT MAX(iHotelID) FROM tHotelBase WHERE LEFT(iHotelID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxHotelID();

	/* 创建酒店信息 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tHotelBase(iHotelID, cHotelName, iZoneID, cHotelCode, cAddress, cContact, cTel, cIntro, cRate, iYear, iRoom, iType, iHeight, cNotice, cFacilities, cEvaluation, cImgPath, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(int iHotelID);

	/* 查找该ID的酒店信息 */
	@Transactional
	@Modifying
	@Query(value = "select * from tHotelBase where iHotelID=?1", nativeQuery = true)
	List<THotelBase> findByiHotelID(int iHotelID);

	/* 删除酒店 */
	@Transactional
	@Modifying
	@Query(value = "delete from tHotelBase where iHotelID in (:iHotelIDs)", nativeQuery = true)
	void deleteChecked(@Param("iHotelIDs") List<Integer> iHotelIDs);
}
